package com.xbongbong.rule.symbol;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.rule.symbol.base.AbstractSymbol;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Objects;

/**
 * 包含任意一个判断
 * 适用类型:复选/下拉复选/关联数据多选/成员多选/部门多选/标签/关联业务多选/子表单
 *
 * @author zheng.li
 **/
public class IncludeSymbol extends AbstractSymbol {

    @Override
    public boolean operation() {
        JSONArray arrayValue = factJson.getJSONArray(attr);
        if (CollectionsUtil.isNotEmpty(arrayValue)) {
            if (attr.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
                for (Object o : arrayValue) {
                    JSONArray array = (JSONArray) o;
                    if (CollectionsUtil.isNotEmpty(array) && CollectionsUtil.isNotEmpty(CollectionUtils.intersection(array, conditionValueList))) {
                        return true;
                    }
                }
            } else {
                return CollectionsUtil.isNotEmpty(CollectionUtils.intersection(arrayValue, conditionValueList));
            }
        }
        return false;
    }
}
